package com.shell.arouter.demo.multitype;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.durian.ui.adapter.multi.Items;
import com.durian.ui.adapter.multi.MultiTypeAdapter;
import com.henanjianye.soon.communityo2o2.R;
import com.shell.arouter.ui.activity.ActivityCommon;


/**
 * 说明：ActivityMulItems
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-10-30 14:26
 * <p/>
 * 版本：version 1.0
 */
public class ActivityMulItems extends ActivityCommon implements SwipeRefreshLayout.OnRefreshListener {

    RecyclerView       rvItems;
    SwipeRefreshLayout swipeRefresh;

    MultiTypeAdapter mAdapter;

    @Override
    protected int getRootViewResID() {
        return R.layout.activity_mul_items;
    }

    @Override
    public void onInitStart() {
        rvItems = findViewById(R.id.rvItems);
        swipeRefresh = findViewById(R.id.swipeRefresh);

        mAdapter = new MultiTypeAdapter();
        mAdapter.setLifecycleOwner(this);
        swipeRefresh.setOnRefreshListener(this);

        mAdapter.register(OneA.A.class, new OneA());
        mAdapter.register(OneB.B.class, new OneB());
        mAdapter.register(OneC.C.class, new OneC());
        mAdapter.register(MoreOneBean.class,new MoreOne());
        mAdapter.register(MoreTwoBean.class,new MoreTwo());

        rvItems.setLayoutManager(new LinearLayoutManager(this));
        rvItems.setAdapter(mAdapter);

        onRefresh();
    }

    int times = 0;
    Items items = new Items();
    @Override
    public void onRefresh() {
        swipeRefresh.setRefreshing(true);
        rvItems.postDelayed(new Runnable() {
            @Override
            public void run() {
                items.clear();
                if (times % 2 == 0){
                    items.add(new MoreOneBean(0));
                    items.add(new OneA.A("1.1"));
                    items.add(new OneA.A("1.2"));
                    items.add(new OneA.A("1.3"));
                    items.add(new OneB.B("2"));
                    items.add(new OneB.B("2.1"));
                    items.add(new OneB.B("2.2"));
                    items.add(new OneB.B("2.3"));
                    items.add(new MoreOneBean(1));
                    items.add(new MoreOneBean(3));
                    items.add(new MoreTwoBean(0));
                    items.add(new MoreTwoBean(1));
                    items.add(new MoreTwoBean(0));
                    items.add(new MoreTwoBean(1));
                    items.add(new MoreOneBean(0));
                    items.add(new MoreOneBean(1));
                    items.add(new MoreOneBean(0));
                    items.add(new MoreOneBean(1));
                    items.add(new OneC.C("3"));
                    items.add(new OneC.C("3.1"));
                    items.add(new OneC.C("3.2"));
                    items.add(new OneC.C("3.3"));

                    mAdapter.refresh(items);
                    swipeRefresh.setRefreshing(false);
                }else {
                    items.add(new MoreTwoBean(1));
                    items.add(new MoreTwoBean(0));
                    items.add(new MoreOneBean(1));
                    items.add(new MoreTwoBean(0));
                    items.add(new MoreOneBean(1));
                    items.add(new MoreTwoBean(0));
                    items.add(new MoreOneBean(1));
                    items.add(new MoreOneBean(0));
                    items.add(new OneA.A("1"));
                    items.add(new OneA.A("1.1"));
                    items.add(new OneA.A("1.2"));
                    items.add(new OneA.A("1.3"));
                    items.add(new OneB.B("2"));
                    items.add(new OneB.B("2.1"));
                    items.add(new OneB.B("2.2"));
                    items.add(new OneB.B("2.3"));
                    items.add(new OneC.C("3"));
                    items.add(new OneC.C("3.1"));
                    items.add(new OneC.C("3.2"));
                    items.add(new OneC.C("3.3"));
                    mAdapter.refresh(items);
                    swipeRefresh.setRefreshing(false);
                }
                times++;
            }
        },1000);
    }

    @Override
    public boolean isShowTitleBar() {
        return true;
    }

    @Override
    public String bindTitleBarText() {
        return "多类型条目";
    }
}
